<?php
include('connect_db.php');
/*if logged in, redirect to homepage */

if (checkLoggedin())
{
	if(ISSET($_GET['house_id']))
	{
		/*check if the user already joined in*/
		$sql = "SELECT * FROM houses_users
						 WHERE user_id = ".$_SESSION['id'].
						 " AND house_id = ".$_GET['house_id'];
		mysql_query($sql);
		$reslut = mysql_fetch_row(mysql_query($sql));

		if(!ISSET($reslut['0']))
		{
			echo $sql = "INSERT INTO houses_users (house_id, user_id)
					   	 VALUES (".$_GET['house_id'].", ".$_SESSION['id'].")";
			mysql_query($sql);
		}
    }
    header('Location: index.php');
}
else
{
	header('Location: login.php');
}